// pages/cash/log/log.js

import {Request} from '../../../utils/request.js';
import mock from '../../../utils/mock.js';
const app = getApp();

Page({

  /**
   * 页面的初始数据
   */
  data: {
    list: [],
    tip: [],
    max: 100,
    min: 1,

    balance: 100,
    totalPage: 0,
    curPage: 1,
    loadingPage: false,
    lastPage: false,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.postCash();
  },

  postCash: function(){
    let that = this;
    let curPage = that.data.curPage;
    let res = mock.walletBill;
    that.setData({
      list: that.data.list.concat(res.list),
      totalPage: res.total_page,
      loadingPage: false,
      lastPage: res.total_page == 1 || res.total_page == curPage,
    });
  },

  //提现
  onCashOut: function() {
    let that = this;
    if(that.data.balance < that.data.min) {
      wx.showToast({title: "最小提现额度为 " + that.data.min + " 元", icon: 'none',duration: 1500 });
      return ;
    }
    wx.navigateTo({
      url: '/pages/profile/cashout/cashout',
    })
  },


  onReachBottom: function () {
    let that = this;
    if(that.data.curPage == that.data.totalPage || that.data.loadingPage) {
      return ;
    }
    that.setData({
      curPage: that.data.curPage + 1,
      loadingPage: true,
    })
    that.postCash();
  },


  onReady: function () {},
  onShow: function () {},
  onHide: function () {},
  onUnload: function () { },
  onPullDownRefresh: function () {},


})